<?php
/**
 * Copyright (c) 2006-2008, Julien PORTALIER
 * http://featherphp.googlecode.com/
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 */

/**
 * Signs the request using an API key / secret pair.
 * 
 * @param $api_key String
 * @param $secret String
 * @param $headers Array
 * @param $params Array
 * @param $method String
 * @param $url String
 */
function & ActiveResource_Authentication_Sig($api_key, $secret, array &$headers, array &$params, $method, $url)
{
	# signs request
	$call_id = microtime(true);
	$headers['X-API-KEY']     = $api_key;
	$headers['X-CALL-ID']     = $call_id;
	$headers['X-SIG-REQUEST'] = base64_encode(sha1($api_key.$call_id.$method.$url.$secret));
	
	# signs params
	if (!empty($params))
	{
		$params['f_api_key'] = $api_key;
		$params['f_call_id'] = $call_id;
		
		$str = '';
		foreach($params as $k => $v)
		{
			$str .= "$k=$v";
		}
		$params['f_sig_params'] = md5($str.$secret);
	}
}
?>